#pragma once

#include "../CCompilerBackend.hpp"

namespace BuildNG
{
  class PkgConfig;

  class GCCCompilerBackend : public CCompilerBackend
  {
  public:
    static Glib::RefPtr<GCCCompilerBackend> create();

    virtual bool build_source_file(
      BuildContext&                 context,
      const Glib::ustring&          source_file_name,
      Glib::ustring&                obj_file_name,
      Glib::RefPtr<ErrorListener>   error_listener);

    virtual bool link(
      BuildContext&                 context,
      const std::vector<Glib::ustring> &object_files,
      Glib::RefPtr<ErrorListener>   error_listener);
      
    // settings related functions
    virtual void add_reference(Glib::RefPtr<CLangReference> reference);
    virtual void set_language(Language language) { assert(!"Not implemented yet"); }

  private:
    Glib::ustring                   get_compiler_path() const;

    // the args that were the result of package resolving.
    Glib::ustring                   cflags_pkg_args;
    Glib::ustring                   libs_pkg_args;

    class ErrorOutputHandler : public EGlib::IProcessOutputHandler
    {
    public:
      virtual void handle_output(char *buffer,int buffer_size);

      void flush();

      std::string cur_line;
      Glib::RefPtr<ErrorListener> error_listener;
    };
  };
}
